// 单独验证某一个input  class="checkpass"
jQuery.validator.addMethod("checkSkuStockName", function (value, element) {
    return this.optional(element) || ((value.length <= 10) && (value.length >= 3));
}, "商品名由3至10位字符组合构成");

$(function () {
    $("form").validate({
        submitHandler: function (form) { // 必须写在验证前面，否则无法ajax提交
            ly.ajaxSubmit(form, { // 验证新增是否成功
                type: "post",
                dataType: "json",
                success: function (data) {
                    if (data == "success") {
                        layer.confirm('更新成功!是否关闭窗口?', function (index) {
                            parent.grid.loadData();
                            parent.layer.close(parent.pageii);
                            return false;
                        });
                    } else {
                        layer.alert('添加失败！', 3);
                    }
                }
            });
        },
        errorPlacement: function (error, element) {//自定义提示错误位置
            $(".l_err").css('display', 'block');
            //element.css('border','3px solid #FFCCCC');
            $(".l_err").html(error.html());
        },
        success: function (label) {//验证通过后
            $(".l_err").css('display', 'none');
        }
    });

});

function byRes(goodId){
    var url = rootPath + '/store/good/findGood.shtml';
    var data = CommnUtil.ajax(url, null,"json");
    if (data != null) {
        var h = "<option value='0'>请选择</option>";
        for ( var i = 0; i < data.length; i++) {
            if(goodId==data[i].id){
                h+="<option value='" + data[i].id + "' selected='selected'>"
                    + data[i].name + "</option>";
            }else{
                h+="<option value='" + data[i].id + "'>"+ data[i].name + "</option>";
            }
        }
        $("#goodId").html(h);
    } else {
        bootbox.alert("获取菜单信息错误，请联系管理员！");
    }
}
